package com.example.binpacking.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.binpacking.model.QuestionnaireName;
import com.example.binpacking.model.Result;
import com.example.binpacking.model.SubjectView;
import com.example.binpacking.model.dto.QuestionNameItemOptionMDDto;
import com.example.binpacking.model.dto.QuestionNamePageDto;
import com.example.binpacking.service.QuestionnaireNameService;
import com.example.binpacking.service.SubjectViewService;
import io.swagger.annotations.ApiOperation;
import net.dreamlu.mica.core.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
@RestController
@RequestMapping("/pelicanpsyc/api")
public class QuestionnaireNameController {
    @Autowired
    private QuestionnaireNameService questionnaireNameService;
    @ApiOperation("分页并进行获得调查问卷")
    @PostMapping ("/getQuestionnaireName")
    public Result getQuestionnaireNameList(@RequestBody QuestionNamePageDto questionNamePageDto) {
        Page<QuestionnaireName> questionnaireName = questionnaireNameService.getQuestionnaireNameByPage(questionNamePageDto.getIsdeleted(),questionNamePageDto.getCurrentpage(),questionNamePageDto.getPagesize());
        return Result.success(questionnaireName);
    }
    @ApiOperation("插入调查问卷")
    @PostMapping("/insertQuestionnaireName")
    public Result insertQuestionnaireName(@RequestBody QuestionnaireName questionnaireName) {
        boolean isSuccess = questionnaireNameService.save(questionnaireName);
        if (isSuccess) {
            return Result.success(questionnaireName);  // 返回传入的对象
        } else {
            return Result.fail("Failed to save questionnaire name.");
        }
    }
    @ApiOperation("修改调查问卷")
    @PostMapping ("/modifyQuestionnaireName")
    public Result modifyQuestionnaireName(@RequestBody QuestionNameItemOptionMDDto questionNameItemOptionMDDto) {
        int i =questionnaireNameService.updateByName(questionNameItemOptionMDDto.getId(),questionNameItemOptionMDDto.getName());
        if(i!=0){
            return Result.success("y");
        }else {
            return Result.fail("n");
        }
    }
    @ApiOperation("删除调查问卷(软删除)")
    @PostMapping ("/deleteQuestionnaireName")
    public Result deleteQuestionnaireName(@RequestBody QuestionNameItemOptionMDDto questionNameItemOptionMDDto) {
        int i =questionnaireNameService.updateDeletedById(questionNameItemOptionMDDto.getId(),questionNameItemOptionMDDto.getIsdeleted());
        if(i!=0){
            return Result.success("y");
        }else {
            return Result.fail("n");
        }
    }

}
